package com.handinglian.ai.common.exception;

/**
 * @author handinglian
 * @description
 * @date 2018/10/30 14:34
 *  业务异常基类，所有业务异常都必须继承于此异常
 *  定义异常时，需要先确定异常所属模块。例如：数据重复报错 可以定义为 [100002] 前三位数为系统模块编号，后三位为错误代码 ,唯一
 *  通用异常  100
 *  百度ai异常  101
 */
public class BizException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    public static final BizException REQUEST_ERROR = new BizException(100001, "操作失败");

    public static final BizException DATA_DUPLICATE = new BizException(100002, "该数据已经存在");

    public static final BizException EXIST_IN_DELETE = new BizException(100003, "该数据已经存在于删除列表中，是否恢复!");

    public static final BizException LOGIN_FAILURE= new BizException(100005, "登录失败!");

    public static final BizException NOT_LOGIN= new BizException(100006, "请先登录!");

    public static final BizException AUTHORIZE_FAIL= new BizException(100007, "没有相关访问权限!!");

    public static final BizException ROLE_USED= new BizException(100008, "角色已被使用，不可删除!");

    public static final BizException STREAM_ERROR= new BizException(100009, "数据流异常");

    public static final BizException OLD_PASSWORD_ERROR= new BizException(100010, "原密码错误，请检查后重新输入！");

    public static final BizException TEMPLATE_USED_ERROR= new BizException(100011, "模板已在使用，不可删除");

    public static final BizException KEY_GROUP_USED_ERROR= new BizException(100012, "按键组已在使用，不可删除");

    /**
     * 异常信息
     */
    protected String msg;

    /**
     * 具体异常码
     */
    protected int code;

    public BizException(int code, String msgFormat, Object... args) {
        super(String.format(msgFormat, args));
        this.code = code;
        this.msg = String.format(msgFormat, args);
    }

    public BizException() {
        super();
    }

    public String getMsg() {
        return msg;
    }

    public int getCode() {
        return code;
    }

    /**
     * 实例化异常
     *
     * @param msgFormat
     * @param args
     * @return
     */
    public BizException newInstance(String msgFormat, Object... args) {
        return new BizException(this.code, msgFormat, args);
    }

    public BizException(String message, Throwable cause) {
        super(message, cause);
    }

    public BizException(Throwable cause) {
        super(cause);
    }

    public BizException(String message) {
        super(message);
    }


}
